import { GoodsDetail, GoodsPageResult, GoodsQuery } from "./types";
import request from "@/utils/request";
import { AxiosPromise } from "axios";

/* 获取商品分页列表 */
export function listSpuPages(
  queryParams: GoodsQuery
): AxiosPromise<GoodsPageResult> {
  return request({
    url: "/mall-pms/api/v1/spu/pages",
    method: "get",
    params: queryParams,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 获取商品详情 */
export function getSpuDetail(id: string): AxiosPromise<GoodsDetail> {
  return request({
    url: "/mall-pms/api/v1/spu/" + id,
    method: "get",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 添加商品 */
export function addSpu(data: object) {
  return request({
    url: "/mall-pms/api/v1/spu",
    method: "post",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 修改商品 */
export function updateSpu(id: number, data: object) {
  return request({
    url: "/mall-pms/api/v1/spu/" + id,
    method: "put",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 删除商品 */
export function deleteSpu(ids: string) {
  return request({
    url: "/mall-pms/api/v1/spu/" + ids,
    method: "delete",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}
